<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/static/common/default.jsp"%>
<html>
	<head>
	    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	    <title>权限管理</title>
	</head>
	<body>
		<div class="breadcrumbs" id="breadcrumbs">
			<script type="text/javascript">
				try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
			</script>
			
			<ul class="breadcrumb">
				<li><i class="icon-home home-icon"></i> <a href="#">首页</a></li>
				<li>用户中心</li>
				<li>菜单管理</li>
				<li class="active">编辑</li>
			</ul>
			
			
		</div>
		
		<div class="page-content">
			<div class="page-header">
				<h1>菜单管理
					<small>
					<i class="icon-double-angle-right"></i>
					编辑		
					</small>					
				</h1>
			</div>
			
			<div class="row">
				<div class="col-xs-12">
				<form class="form-horizontal" onsubmit="return sysResourceInfoUpdate();" role="form" id="sysResourceUpateForm" name="sysResourceUpateForm" method="post">	
					<div class="form-group">
						<label class="col-sm-3 control-label no-padding-right" for="form-field-1">名称: </label>
						<div class="col-sm-9">
							<input type="text" id="resName" type="text" name="resName" value="${resouce.resName}" class="validate[required,maxSize[100]]" class="col-xs-10 col-sm-5" />
						</div>
					</div>
					<div class="space-4"></div>
					
					<div class="form-group">
						<label class="col-sm-3 control-label no-padding-right" for="form-field-1">URL: </label>
						<div class="col-sm-9">
							<input type="text" id="resUrl" type="text" name="resName" value="${resouce.resUrl}" class="validate[required,maxSize[100]]"  />
						</div>
					</div>
					<div class="space-4"></div>
					
					<div class="form-group">
						<label class="col-sm-3 control-label no-padding-right" for="form-field-1">类型: </label>
						<div class="col-sm-9">
							<select id="type" name="type">
								<option  value="1" <c:if test="${resouce.type==1}">selected</c:if>>菜单</option>
								<option value="2" <c:if test="${resouce.type==2}">selected</c:if>>按钮</option>
							</select>
						</div>
					</div>
					<div class="space-4"></div>
					
					<div class="form-group">
						<label class="col-sm-3 control-label no-padding-right" for="form-field-1">序号: </label>
						<div class="col-sm-9">
							<input type="text" id="indexNum" type="text" name="indexNum" value="${resouce.indexNum}" class="validate[required,maxSize[100]]" />
						</div>
					</div>
					<div class="space-4"></div>
					
					<div class="form-group">
						<label class="col-sm-3 control-label no-padding-right" for="form-field-1">父菜单: </label>
						<div class="col-sm-9">
							<select id="parentId" name="parentId">
								<option class="department_opt" value="-1">无</option>
								<c:forEach var="list" items="${list}" varStatus="status">
									<option class="department_opt" value="${list.resourceId}" <c:if test="${list.resourceId==resouce.parentId}">selected</c:if>>${list.resName}</option>
								</c:forEach>		
							</select>
						</div>
					</div>
					<div class="space-4"></div>
					<input id="resourceId" type="hidden" name="resourceId" value="${resouce.resourceId}"/>
					<input id="resDesc" type="hidden" name="resDesc" value="${resouce.resDesc}"/>
					
					<div class="clearfix form-actions">
							<div class="col-md-offset-3 col-md-9">
								<button class="btn btn-info" type="submit">
									<i class="icon-ok bigger-110"></i>提交
								</button>
							</div>
					</div>
				</form>
				</div>
							
			</div>					
		</div>
		
		<script type="text/javascript">
			function sysResourceInfoUpdate() {
				/*alert('dddd');
				alert($("#sysResourceUpateForm").validationEngine("validate"));
				return false; */
				if (true) {
				//if (true) {
					//alert('111');
					var datastr = new Object();
	    			datastr.resName = $('#resName').val();
	    			datastr.resUrl = $('#resUrl').val();
	    			datastr.indexNum = $('#indexNum').val();
	    			datastr.parentId = $('#parentId').val();
	    			datastr.resDesc = $('#resDesc').val();
	    			datastr.type = $('#type').val();
	    			datastr.resourceId = $('#resourceId').val();
					var result = true;
					$.ajax({
	    		        async: true,
	    		        type:"POST",
	    		        data:JSON.stringify(datastr),
	    		        url: "${ctx}/sys/resource/update/"+datastr.resourceId,
	    		        dataType: "json",
	    		        headers : {  
	                        'Content-Type' : 'application/json;charset=utf-8'  
	                    },
	                    success : function(data) {
	                		if (data != undefined && data.status != undefined
	                				&& data.status.trim() == '0') {
	                			result = true;
	                			alert("修改成功！");
	                			window.location.href = "${ctx}/sys/resource/list";
	                		} else {
	                			result = false;
	                			alert(data.error);
	                		}
	                	},
	    			},"json");
				}
				return false; 
			}
		</script>
	</body>
</html>